import { createWebHistory, createRouter } from 'vue-router'
import Layout from '@/layout/index.vue'
export const constantRoutes = [
    {
        path: '/login',
        component: () => import('@/views/login.vue'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: '/index',
        children: [
            {
                path: 'index',
                name: 'index',
                meta: { title: "首页", icon: "HomeFilled", affix: true, noCache: true },
                component: () => import('@/views/index.vue')
            }
        ]
    },
    {
        path: '/personal',
        component: Layout,
        hidden: true,
        children: [
            {
                path: 'index',
                name: 'personalCenter',
                meta: { title: "个人中心" },
                component: () => import('@/views/personal/index.vue')
            }
        ]
    },
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                meta: { title: '首页' },
                component: () => import('@/views/redirect/index.vue')
            }
        ]
    },
    {
        path: '/404',
        component: () => import('@/views/error/404.vue'),
        hidden: true
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes: constantRoutes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { top: 0 }
        }
    },
})

export default router